package com.chixing.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * 获得dbconn.properties文件中的参数
 */
public class DataSourceFileUtil {
    private static Properties properties;
    //读取dbconn.properties文件，用static修饰是为了只加载一次，减少了IO操作
    static {
        properties=new Properties();
        //‘/’是这个文件运行的根目录下去找的
        InputStream is=DataSourceFileUtil.class.getResourceAsStream("/dbconn.properties");
        try {
            properties.load(is);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    //1.读取文件
    public static String getDriverName(){
        return properties.getProperty("driverName");
    }
    public static String getDriverURL(){
        return  properties.getProperty("url");
    }
    public static String getDriverUsername(){
        return  properties.getProperty("username");
    }
    public static String getPassword(){
        return properties.getProperty("password");
    }

    public static void main(String[] args) {
        System.out.println(getDriverName());
        System.out.println(getDriverURL());
    }
}
